package com.zhuimeng.Application.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class MapCodeUils {
    private static Map<String, List> codeMap = new ConcurrentHashMap<>();

    public static void putCode(String key, String code) {
        List list = new ArrayList();
        list.add(code);
        list.add(System.currentTimeMillis());

        codeMap.put(key, list);
    }

    public static String getCode(String key) {
        if (codeMap.containsKey(key)) {
            List valList = codeMap.get(key);
            String code = (String) valList.get(0);
            long setTime = (long) valList.get(1);
            long nowTime = System.currentTimeMillis();
            if (nowTime - setTime > 10 * 60 * 1000) {
                codeMap.remove(key);
                return null;
            }
            return code;
        }
        return null;
    }

    public static void removeCode(String key) {
        codeMap.remove(key);
    }
}
